<% title _("Puppet Classes") %>

<% title_actions import_proxy_select(hash_for_import_environments_puppetclasses_path),
                 documentation_button('4.2.2Classes') %>

<table class="<%= table_css_classes 'table-fixed' %>">
  <thead>
    <tr>
      <th class="col-md-3"><%= sort :name, :as => s_("Puppetclass|Name") %></th>
      <th class="col-md-3"><%= sort :environment, :as => _("Environments") %></th>
      <th class="col-md-2"><%= _('Host Groups') %></th>
      <th class="col-md-1"><%= _('Hosts') %></th>
      <th class="col-md-1"><%= _('Parameters') %></th>
      <th class="col-md-1"><%= _("Actions") %></th>
    </tr>
  </thead>
  <tbody>
    <% for puppetclass in @puppetclasses %>
      <tr>
        <td class="ellipsis"><%=link_to_if_authorized puppetclass.name, hash_for_edit_puppetclass_path(:id => puppetclass).merge(:auth_object => puppetclass, :authorizer => authorizer) %></td>
        <td class="ellipsis">
          <%= puppetclass.environments.uniq.to_sentence %>
        </td>
        <td class=""><%= puppetclass.all_hostgroups(false).map {|hg| link_to_if_authorized trunc_with_tooltip(hg, 24), hash_for_edit_hostgroup_path(:id=>hg).merge(:auth_object => hg, :authorizer => @hostgroups_authorizer)}.to_sentence.html_safe %></td>
        <td><%= link_to puppetclass.hosts_count, hosts_path(:search => "class = #{puppetclass.name}")%></td>
        <td><%= puppetclass.class_params.size %> </td>
        <td>
          <%
          links = [display_delete_if_authorized(hash_for_puppetclass_path(:id => puppetclass).merge(:auth_object => puppetclass, :authorizer => authorizer), :data => { :confirm => _("Delete %s?") % puppetclass.name }, :action => :delete)]
          links.push(display_link_if_authorized(_('Override all parameters'), hash_for_override_puppetclass_path(:enable => true, :id => puppetclass).merge(:auth_object => puppetclass, :authorizer => authorizer, :permission => 'edit_puppetclasses'), :method => :post, :data => { :confirm => _("This will set all parameters of the class %s as overridden. Continue?") % puppetclass.name })) if puppetclass.class_params.present? && !overridden?(puppetclass)
          links.push(display_link_if_authorized(_('Set parameters to defaults'), hash_for_override_puppetclass_path(:enable => false, :id => puppetclass).merge(:auth_object => puppetclass, :authorizer => authorizer, :permission => 'edit_puppetclasses'), :method => :post, :data => { :confirm => _("This will reset parameters of the class %s to their default values. Continue?") % puppetclass.name })) if puppetclass.class_params.present? && overridden?(puppetclass)
          %>
          <%= action_buttons(*links) %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>

<%= will_paginate_with_info @puppetclasses %>
